<#if authority.is(5,"9") >
<table width="100%" height="100px">
	<tr><td>
		<table width="100%" border=1 bgcolor="#ffffff">
			<tbody><tr><td><h4><span id="tip.username" /></h4></td></tr></tbody>
			<tr><td>当前操作: <div id="tip.auth" /></td></tr>
		 	<tr><td>请选择要分配的权限类型<div id="div.authkind.user.auth"/></td></tr>
		 	<tr><td>请选择扩展权限<div id="div.authdyna.auth"/></td></tr>
		 	<tr><td align="center"><input type="button" id="auth.setter.save" name="auth.setter.save" value="确定">
		 		<div id="auth.setter.saving"></div></td></tr>
		 </table>
		 
		</td>
	    <td valign="top">
	    	该用户已拥有的节点权限(不包含用户所属角色)<span><a href="#" id="auth.del.userauth" name="auth.del.userauth">删除</a></span> 
		 	<div id="div.userAuth">
		</td>
 	</tr>
</table>
 

<script type="text/javascript">
var dataURL = '/data/sc.action';//取数据的url
 

//填充该角色已拥有的节点权限(不包含用户所属角色)
var userAuth=null;

var loadUserAuthList = function(){
	var	columns = [{text:'序号',name:'id'},{text:'节点名称',name:'nodename'},{text:'权限类型',name:'kindname'}];//要显示的字段
	var	dataURLParams = {"scid":"authsetter_1", "id":item_value, "mode":1};
	if (!userAuth){
		userAuth = new MUI.List({
			instanceName: 'userAuth',
	       	container:'div.userAuth',
	       	showCheckBox:true,
			showCommand:false,
	       	id: "userAuthList",
	       	columns:columns,
	       	dataURL:dataURL,
	       	dataURLParams: dataURLParams,
	       	cbName: 'idsuserAuth',
	       	saveCheck:true,
	       	commands:[]
	   	});//MUI.List
   	}
   	userAuth.setDataURLParams(dataURLParams);
   	userAuth.findList(1,true);
}

    
window.addEvent('domready', function() {
	new MUI.Require({
	  js: [MUI.path.plugins + 'mochaList/List.js'],
	  onload: function(){
		if(nodeinfo==null || nodeinfo.kind==0){
			//如果取不到节点,比如初始化界面时,或选中静态权限时
			$('div.authdyna.auth').set('html','');
		}
		$('tip.auth').set('html','<font color=red>必须选择权限树节点</font>');
		//通过userID取得角色名称,并显示在页面上
		try {
			var request = new Request.JSON({
			url: dataURL,
			onComplete: function(json,text) {
				if (json.error.errorcode==0){
    				 $('tip.username').set('html','为用户['+json.recorders[0]['username']+']分配权限操作');
    			}else{
    				MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
    			}
			}
		}).get({"scid":"user_2","id": item_value});
		} catch (ex) {
			MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
		}
		loadUserAuthList();
	  } 
	}); 
	
	$('auth.setter.save').addEvent('click', function(e){
		var checkids_dynanodeset = '';	//保存扩展权限勾选项
		var dataURLParams = ''; 
		var authids = ''; //选择的树节点ID,静态权限时是一个以逗号分隔的ID字串,
						  //扩展权限时是一个单字符串(即nodeinfo.id),
						  //用户最终选择的树节点ID保存在这里,并传到脚本处理
		if(-1 == nodetype)  {MUI.notification('<font color=red>错误：</font>(必须选择权限节点!)'); return;}
		if(0 == nodetype) {
			//当前操作静态节点
			authids = findIds();
			if(authids=='') {MUI.notification('<font color=red>错误：</font>(必须选择权限节点!)'); return;}
		}else{
			//当前操作扩展权限
			if(!dynanodeset) {MUI.notification('<font color=red>错误：</font>(无法取得扩展权限!)'); return;}
			if(nodeinfo==null) {MUI.notification('<font color=red>错误：</font>(必须选择权限节点!)'); return;}
			authids = nodeinfo.id;
			checkids_dynanodeset = dynanodeset.getcurCheckIds();
			if(null==checkids_dynanodeset || ""==checkids_dynanodeset) { alert('必须选择一项要添加的扩展权限'); return; }
			checkids_dynanodeset = checkids_dynanodeset + "";
		}
		//权限类型的检查
		if(!userAuthKind) {MUI.notification('<font color=red>错误：</font>(无法取得权限类型!)'); return;}
		var checkids_kinds = userAuthKind.getcurCheckIds();
		if(null==checkids_kinds || ""==checkids_kinds) { alert('必须选择一项要添加的权限种类'); return; }
		checkids_kinds = checkids_kinds + "";
		
		$('auth.setter.save').set('disabled', true);
		$('auth.setter.saving').innerHTML = '<img src="images/spinner.gif" width="16px" height="16px">';
		
		if( 0 == nodetype ){
			dataURLParams = {"scid":"authsetter_3", 
				"authids":authids, "userAuthKind":checkids_kinds, "userid":item_value};
		}else if( 1 == nodetype ){	
			dataURLParams = {"scid":"authsetter_4", 
				"authids":authids, "dynanodeset":checkids_dynanodeset, 
				"userAuthKind":checkids_kinds, "userid":item_value};
		}
		
		try {
			var request = new Request.JSON({
			url: dataURL,
			onComplete: function(json,text) {
    				confirmWindow('保存结果',json.error.retstring);
    				loadUserAuthList();
    				//所有元素还原默认值
					nodetype = -1;	
					nodename.empty();
					cancelAll();
					userAuthKind.clearCheckIds();
					userAuthKind.cancelAll();
					if(dynanodeset){
						dynanodeset.clearCheckIds();
						dynanodeset.cancelAll();
					}
				$('tip.auth').set('html','<font color=red>必须选择权限树节点</font>');
    			$('auth.setter.save').set('disabled', false);
				$('auth.setter.saving').innerHTML = '';
			}
		}).get(dataURLParams);
		} catch (ex) {
			MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
			$('auth.setter.save').set('disabled', false);
			$('auth.setter.saving').innerHTML = '';
		}
	});
	
	$('auth.del.userauth').addEvent('click', function(e){
		if(!userAuth) return;
		checkids_userAuth = userAuth.getcurCheckIds();
		if(null==checkids_userAuth || ""==checkids_userAuth) { 
			alert('必须选择一项要删除的用户权限'); 
			return; 
		}else{
			var confirm = confirmWindow('删除权限','确定要删除选中的用户对应的权限吗？<input id="comfirm" type="button" value="确定" ><input id="cancel" type="button" value="取消" >');
			$('comfirm').addEvent('click',function(e){
				confirm.close();
				checkids_userAuth = checkids_userAuth + "";
				userAuth.clearCheckIds();
				var dataURLParams = {"scid":"authall_del", "checkids_allAuth":checkids_userAuth};
				 try {
					var request = new Request.JSON({
					url: dataURL,
					onComplete: function(json,text) {
						if (json.error.errorcode==0){
		    				MUI.notification('删除成功！');
		    				loadUserAuthList();
		    			}else{
		    				MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
		    			}
					}
				}).get(dataURLParams);
				} catch (ex) {
					MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
				}
			}); 
			$('cancel').addEvent('click',function(e){
				confirm.close();
			});
		}
		});
	
});
</script>
 <#else>
您无权访问该页面！
</#if>